﻿package Welsy4.Connect.business
{
	import flash.net.URLVariables;
	import Welsy4.Connect.vo.User;	
	import Welsy4.Connect.model.ConnectModel;
	import com.adobe.cairngorm.business.ServiceLocator;	
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.http.HTTPService;

	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class CreateUserDelegate 
	{
		private var responder : IResponder;
        private var service : Object;
                
        public function CreateUserDelegate( responder : IResponder )
        {
            this.service = ServiceLocator.getInstance().getHTTPService("FakeAPI" );
            this.responder = responder;
        }
		
		public function CreateNewUser(user:User):void {
			
			var newUserURI:URLVariables = new URLVariables();
			
			/*
			 * field requested
			 */
			newUserURI.action       =  "principal-update";
			newUserURI.login        =  user.nickname;
			newUserURI.password    =  User.generatePassword(user.nickname);
			newUserURI.type         =  "user";
			newUserURI.session      =  ConnectModel.getInstance().sessionCookie;
						
			newUserURI.decode("first-name="+user.nome);
			newUserURI.decode("last-name="+user.cognome);
			newUserURI.decode("has-children=0");
			
			
			var token : AsyncToken = HTTPService(service).send(newUserURI);
			token.addResponder(responder);
		}
		
		public function getUserInfo(user:User):void {
			var token : AsyncToken = HTTPService(service).send(new URLVariables("createuser=false"));
			token.addResponder(responder);
		}
		
		public function createMeetingRoom():void {
		    // catena di chiamate per generare la meeting room
			// ottengo la sco - id
			
			var token : AsyncToken = HTTPService(service).send(new URLVariables("action=sco-shortcut"));
			token.addResponder(responder);
		
		}
		
		public function getMeetingRoomURL(user:User):void {
		    // require you are logged in	
		}
	}
	
}